import java.util.ArrayList;
import java.util.Scanner;
public class Administor {
    private String name ;
    private String password ;
    public Administor(String name, String password) {
        this.password = password;
        this.name = name;
    }
    public void setName(String name) {
        this.name = name;
    }
    public String getName() {
        return name;
    }
    public void setPassword(String password) {
        this.password = password;
    }
    public String getPassword() {
        return password;
    }
    public void login() {
        Scanner reader = new Scanner(System.in);
        System.out.println("请输入您的账户：");
        String account = reader.next();
        System.out.println("请输入您的密码");
        String password1 = reader.next();
        if ((account.equals(name))&&(password1.equals(password))) {
            System.out.println("管理员登陆成功");
        }
        else {
            System.out.println("密码错误，管理员登陆失败");
            login();
        }
    }
    public void passwordMng(){
        System.out.println("请输入原来的密码：");
        Scanner reader = new Scanner(System.in);
        String oldPassword=reader.next();
        if(oldPassword.equals(password)){
            System.out.println("请输入您的新密码：");
            String newPassword=reader.next();
            this.password=newPassword;
        }
        else System.out.println("原来的密码错误,请重新输入！");
    }
    public void resetUserpassword(ArrayList<User>userList){
       System.out.println("请输入客户名：");
       Scanner reader=new Scanner(System.in);
       String username=reader.next();
       for(User user:userList){
           if(username.equals(user.getName())){
               System.out.println("请输入新密码：");
               String newPassword=reader.next();
               user.setPassword(newPassword);
               System.out.println("新密码设置成功！");
           }
       }
    }
    public void listUserInfo(ArrayList<User>userList){
        for (User user : userList) {
            System.out.println("ID:"+user.getID()+"   用户名："+user.getName()+"   用户级别："+user.getLevel()+"   用户注册日期："+user.getDate()+"   客户累积消费总金额："+user.getMoney()+"   用户手机号："+user.getPhone()+"   用户邮箱:"+user.getEmail());
        }
    }
    public void delUserInfo(ArrayList<User>userList){
        System.out.println("请输入您想删除的客户名：");
        Scanner reader = new Scanner(System.in);
        int m=0;
        String username=reader.next();
        for(User user:userList){
            if(username.equals(user.getName())){
                System.out.println("请再次确认您是否要删除该客户信息（yes or no）");
                String isYes=reader.next();
                if(isYes.equals("yes")){
                userList.remove(m);
                System.out.println("您已成功删除该客户的信息！");
                break;
                }
            }
            m++;
        }
    }
    public void findInfo(ArrayList<User>userList){
        System.out.println("请输入您想查询用户的用户名或用户ID：");
        Scanner reader = new Scanner(System.in);
        String usernameOrID=reader.next();
        int m=0;
        for(User user:userList){
            if((usernameOrID==user.getID())||(usernameOrID==user.getName())){
                System.out.println(userList.get(m));
            }
            m++;
        }
    }

}
